function [ bnd ] = messageMultiplication2(beliefs, ndists, proposal, var_m)

[N_samples, ~] = size(proposal);
[nh_msg, ~] = size(beliefs);

%calculate weigths
wtmp1 = 1;
for i=1:nh_msg
    tmp = beliefs{i};
    [numEl, ~] = size(tmp);
    
    if(numEl == 2)
        dist_sq = (proposal(:,1)-tmp(1)).^2+(proposal(:,2)-tmp(2)).^2;
        wtmp = exp(-1/(2*var_m) * (ndists(i) - sqrt(dist_sq)).^2);
    else
        wtmp = zeros(N_samples,1);
        for j=1:N_samples
            dist_sq = (proposal(j,1)-tmp(:,1)).^2+(proposal(j,2)-tmp(:,2)).^2;
            wtmp(j) = sum(exp(-1/(2*var_m) * (ndists(i) - sqrt(dist_sq)).^2));
        end
    end
    wtmp1 = wtmp1 .* wtmp;
    wtmp1 = 10^10 * 1/sum(wtmp1) * wtmp1;
end

weights = wtmp1;

%normalise weights
weights = 1/sum(weights) * weights;

if( (sum(isnan(weights)) + sum(isinf(weights))) > 0)
    bnd = NaN*ones(N_samples,4);
    return
end

%resample
tmp = resampleSystematic(weights,N_samples);

bnd = proposal(tmp,:);
end

